package jmine.tec.web.wicket.model;

import java.util.Map;

import org.apache.wicket.model.IModel;

/**
 * {@link IModel} que grava os dados de fato em um {@link Map} de {@link String} para {@link Object}
 * 
 * @author takeshi
 * @param <V>
 */
public class MapBasedModel<V> implements IModel<V> {

    private final Map<String, Object> backingMap;

    private final String key;

    /**
     * C'tor
     * 
     * @param backingMap o mapa
     * @param key a chave para ser usada
     */
    public MapBasedModel(Map<String, Object> backingMap, String key) {
        super();
        this.backingMap = backingMap;
        this.key = key;
    }

    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    public V getObject() {
        return (V) backingMap.get(key);
    }

    /**
     * {@inheritDoc}
     */
    public void setObject(V object) {
        backingMap.put(key, object);
    }

    /**
     * {@inheritDoc}
     */
    public void detach() {
    }

}
